// pages/index/evaluate/evaluate.js
var app = getApp();
import Api from '../../../api/api.js';
const api = new Api();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    canEvaluate:true,
    userId:'',
    contentId:"",
    contentType:"",
    parentCommentId:"",
    content:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.contentId = options.id;
    this.data.contentType = options.contentType;
    this.data.parentCommentId = options.parentCommentId;

  },
  evaluateInput(e){
    this.data.content = e.detail.value;
    console.log(this.data.content);
  },
  evaluateClick(){
    if (this.data.content.length == 0){
      app.alert("请先输入评论类容");
      return;
    }
    if (!this.data.canEvaluate)return;
    this.data.canEvaluate = false;
    var _this = this;
    var map = {};
    map.content = this.data.content;
    map.contentId = this.data.contentId;
    map.contentType = this.data.contentType;
    map.headimg = wx.getStorageSync("headImage");
    map.nickname = wx.getStorageSync("nickName");
    map.parentCommentId = this.data.parentCommentId;
    map.userId = app.USER_ID();
    console.log(JSON.stringify(map));
    api.getRequestData(app.evalueSaveUrl, map, false, "POST").then(res => {
      _this.data.canEvaluate = true;
      if (res.data.errorCode == 0) {
        app.alert("评论成功～");
        setTimeout(function(){
          var page = getCurrentPages();
          var upPage = page[page.length - 2];
          upPage.setData({
            isNeedFresh: true
          });
          wx.navigateBack({});
        },1400);

      } else {
        wx.showToast({
          title: res.data.errorMsg,
          icon: 'none',
          duration: 1500
        });
      }

    }).catch(err => { 
      _this.data.canEvaluate = true;
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})